<?php
/**
 * Created by PhpStorm.
 * User: macp
 * Date: 2017/1/10
 * Time: 14:20
 */

namespace App\Repositories;

use App\Product;
use DB;

class ProductRepository extends CommonRepository
{
	protected $model ;

	public function __construct(Product $product)
	{
		$this->model = $product;
	}


	/**
	 * @author wxh
	 * 通过user_id获取所在经销商的可用的产品信息
	 * @param $user_id
	 * @return mixed
	 */
	public function getListByUser($user_id)
	{
		// 获取所属经销商的产品
		$products = User::find($user_id)
			->dealer()
			->with(['products' => function($query) {
				return $query->where('status', 1)->with('product.material');
			}])
			->first();
		return $products;
	}
}